// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Core.Search;

public sealed partial class PhraseSuggestCollate
{
	/// <summary>
	/// <para>Parameters to use if the query is templated.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("params")]
	public IDictionary<string, object>? Params { get; set; }

	/// <summary>
	/// <para>Returns all suggestions with an extra `collate_match` option indicating whether the generated phrase matched any document.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("prune")]
	public bool? Prune { get; set; }

	/// <summary>
	/// <para>A collate query that is run once for every suggestion.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("query")]
	public Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQuery Query { get; set; }
}

public sealed partial class PhraseSuggestCollateDescriptor : SerializableDescriptor<PhraseSuggestCollateDescriptor>
{
	internal PhraseSuggestCollateDescriptor(Action<PhraseSuggestCollateDescriptor> configure) => configure.Invoke(this);

	public PhraseSuggestCollateDescriptor() : base()
	{
	}

	private IDictionary<string, object>? ParamsValue { get; set; }
	private bool? PruneValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQuery QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQueryDescriptor QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQueryDescriptor> QueryDescriptorAction { get; set; }

	/// <summary>
	/// <para>Parameters to use if the query is templated.</para>
	/// </summary>
	public PhraseSuggestCollateDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		ParamsValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>Returns all suggestions with an extra `collate_match` option indicating whether the generated phrase matched any document.</para>
	/// </summary>
	public PhraseSuggestCollateDescriptor Prune(bool? prune = true)
	{
		PruneValue = prune;
		return Self;
	}

	/// <summary>
	/// <para>A collate query that is run once for every suggestion.</para>
	/// </summary>
	public PhraseSuggestCollateDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQuery query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public PhraseSuggestCollateDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQueryDescriptor descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public PhraseSuggestCollateDescriptor Query(Action<Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQueryDescriptor> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ParamsValue is not null)
		{
			writer.WritePropertyName("params");
			JsonSerializer.Serialize(writer, ParamsValue, options);
		}

		if (PruneValue.HasValue)
		{
			writer.WritePropertyName("prune");
			writer.WriteBooleanValue(PruneValue.Value);
		}

		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Core.Search.PhraseSuggestCollateQueryDescriptor(QueryDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}